﻿@model RBS.Core.Model.U_Friends
@{
    ViewBag.Title = "添加好友";
    Layout = "~/Views/Shared/_UserLayout.cshtml";
} 
<!--导航栏-->
@{
    @Html.Partial("_Location");
}
<!--/导航栏-->
 
@using (Ajax.BeginForm("FriendsEdit",new AjaxOptions()))
{
    @Html.AntiForgeryToken()
    @Html.ValidationSummary(true) 
    <div class="tab-content">
        
        <dl>
            <dt>好友姓名</dt>
            <dd >
                @Html.TextBoxFor(model => model.FriendName, null, new { @class = "input normal",datatype="m",sucmsg="如果系统没此用户则会给您的好友发送注册短信" }) <input type="button" id="btnsearch" value="搜索" class="btn1 w100" />
               <br/><span class="Validform_checktip">请输入手机号，如果系统没此用户则会给您的好友发送注册短信</span>
                @Html.HiddenFor(model => model.FriendId) 
                <br/>
                <table id="user" width="100%" class="ltable">  
                </table> 
                <script type="text/template" id="UserList"> 
                       <tr>
                         <td><input type="radio" id="radioUserId"  name="radioUserId" onclick='selectval(this)'  uid="{{Mobile}}"  value="{{Id}}" /></td>
                        <td>帐号：{{U_Name}}({{U_Uid}})&nbsp;&nbsp;</td> 
                        <td> {{Mobile}}&nbsp;&nbsp;</td> 
                        <td> {{Email}}&nbsp;&nbsp;</td> 
                     </tr>
                     </script> 
            </dd>
        </dl>
        <dl>
            <dt>描述</dt>
            <dd>
                @Html.TextAreaFor(model => model.Remark, 5, 50, new { @class = "input normal" }) 
               
            </dd>
        </dl>
    </div>
    <!--/内容--> 
    <!--工具栏-->
    <div class="page-footer">
        <div class="btn-list">
            <input type="submit" value="提交保存" class="btn" />
            <input name="btnReturn" type="button" value="返回上一页" class="btn yellow" onclick="javascript: history.back(-1);" />

        </div>
        <div class="clear"></div>
    <!--/工具栏-->
      </div>  
} 
@{
    <script src="~/Scripts/mustache.js"></script>
    <script>

        $(function () {
              
            
            $("#btnsearch").click(function () {
                if ($.trim($("#FriendName").val()) == "") {
                    $.dialog.alert("请输入您请输入手机号进行查找！");
                    return false;
                }
                var url = '@Url.Action("QuickSearch")?term=' + $("#FriendName").val();
                $.ajax({
                    url: url,
                    type: "Get",
                    dataType: 'json',
                    success: function(result) {

                        if (result == null)
                            return;
                        $('#user').empty();
                        $.each(result, function(index, row) {
                            var template = $('#UserList').html();//获取模版的html 
                            var bookData = Mustache.render(template, row); //把每行的数据填充到模版得到html内容 
                            $("#user").append(bookData);
                        });
                    }
                });
            });
        });
         
        function selectval(v) {
            var uid = $(v).attr("uid");
            var val = $(v).val(); 
            $("#FriendName").val(uid);
            $("#FriendId").val(val);

        }
    </script>
}
 




